home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jazlib.arc / JZGETPCE.C < prev    next >
Text File  |  1988-12-18  |  1KB  |  38 lines

  1. /*
  2. ┌────────────────────────────────────────────────────────────────────────────┐
  3. │jzgetpce.c                                     │
  4. │Return a delimited portion of a string.                     │
  5. │                                         │
  6. │Parms                                         │
  7. │   fsource : source string with delimiters                     │
  8. │   fdestin : destin string to be returned                     │
  9. │   fdel    : char which is to be used as a delimiter                 │
  10. │   fnum    : which occurrance of the delimited string do you want? (base 1) │
  11. │                                         │
  12. └────────────────────────────────────────────────────────────────────────────┘
  13. */
  14.  
  15. char *jzgetpce(fsource , fdestin , fdel , fnum )
  16. char *fsource , *fdestin , fdel;
  17. int fnum;
  18. {
  19.   char *p;
  20.   int w;
  21.   int wcount;
  22.  
  23.   wcount = 1;                /* search for specified piece */
  24.   while (*fsource && (wcount < fnum))
  25.     if (*fsource++ == fdel)
  26.       wcount ++;
  27.  
  28.   if ((w = index(fsource,fdel)) != -1) {  /* this is not the last piece */
  29.     strncpy(fdestin,fsource,w);
  30.     *(fdestin+w) = 0;
  31.   }
  32.   else
  33.     strcpy(fdestin,fsource);
  34.  
  35.   return(fdestin);
  36.  
  37. }
  38.